<template>
  <div>
    <el-dialog :visible.sync='isShow' title='修改交易组' width="800px" @open="openDialogInit" @close="resetForm" :close-on-click-modal=false>
      <div v-loading="loading">
        <el-card>
          <el-form :model="formInline" ref="formInline" size="mini" :rules="rules" label-position="left" label-width="125px">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label='应用编号'>
                  <el-select v-model="formInline.appnum" disabled placeholder="请选择应用编号">
                    <el-option v-for="item in appQueryList" :key="item.devState" :label="item.AppName" :value="item.AppNum">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="交易组编号:" prop="TranGroupNum">
                  <el-input v-model="formInline.trangroupnum" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="交易组名称:" prop="trangroupname">
                  <el-input v-model="formInline.trangroupname" placeholder="请输入交易组名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label='交易组分类' prop='trangroupclass'>
                  <el-select v-model="formInline.trangroupclass" placeholder="请选择交易组分类">
                    <el-option v-for="item in TranGroupClass" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="法人号:" prop="LegalPersonNum">
                  <el-input v-model="formInline.legalpersonnum" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人名称:" prop="LegalPersonName">
                  <el-input v-model="formInline.LegalPersonName" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="生效日期:" prop="effedate">
                  <el-date-picker v-model="formInline.effedate" value-format="yyyyMMdd" :disabled="true" type="date" placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="失效日期:" prop="expidate">
                  <el-date-picker v-model="formInline.expidate" value-format="yyyyMMdd" type="date" placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label='交易组状态' prop='trangroupstatus'>
                  <el-select v-model="formInline.trangroupstatus" placeholder="请选择交易组分类">
                    <el-option v-for="item in TranGroupStatus" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="排序号:" prop="sortnum">
                  <el-input-number v-model="formInline.sortnum" :min="1" :max="10" label="描述文字"></el-input-number>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
        <el-row style="margin:20px 0;text-align:right">
          <el-button size="mini" @click="closeDialog">取消</el-button>
          <el-button type="primary" size="mini" @click="modTranGroup">确认</el-button>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import request from "@/common/utils/request";
import tranGroup from "@/message/branchManage/tranGroupManage/tranGroup";
import tranGroupNum from "@/message/branchManage/tranGroupManage/tranGroupNum";
export default {
  props: { option: Object },
  data() {
    let expiDateChek = (rule, value, callback) => { //自定义表单验证 校验IP地址
      console.log(value);
        if (value != "") {
          if (value - this.formInline.effedate >= 0) {
            callback();
          } else {
            callback(new Error("失效日期必须大于生效日期"));
          }
        } else {
          callback();
        }
      };
    return {
      loading: false,
      appQueryList: [],
      formInline: {
        LegalPersonName:""
      },
      AppNum: "",
      TranGroupStatus: [
        {
          value: "0",
          label: "0-停用"
        },
        {
          value: "1",
          label: "1-启用"
        }
      ],
      TranGroupClass: [
        {
          value: "01",
          label: "01-机构组"
        },
        {
          value: "02",
          label: "02-设备应用"
        }
      ],
      rules: {
        trangroupname: [
          { required: true, message: "请输入交易组名称", trigger: "blur" }
        ],
        effedate: [
          { type: 'string', required: true, message: '请选择日期', trigger: 'change' }
        ],
        expidate: [
          { type: 'string', required: true, message: '请选择日期', trigger: 'change' },{validator: expiDateChek,trigger: "change"}
        ],
        trangroupclass: [
          { required: true, message: "请选择应用分类", trigger: "change" }
        ],
        trangroupstatus: [
          { required: true, message: "请选择应用组状态", trigger: "change" }
        ],
        sortnum: [
          { required: true, message: "请输入排序号", trigger: "blur" }
        ],
      }
    };
  },
  computed: {
    isShow: {
      get: function() {
        return this.option.isShow;
      },
      set: function(newValue) {
        this.option.isShow = newValue;
      }
    }
  },
  methods: {
    openDialogInit() {
      console.log(this.option)
      this.formInline = this.option.currentRow
      this.formInline.legalpersonnum = this.$store.getters.LegalPersonNum;
      this.formInline.LegalPersonName = this.$store.getters.LegalPersonName;
     
    },

    resetForm() {
      this.$refs["formInline"].resetFields();
    },
    modTranGroup() {
      this.$refs["formInline"].validate(valid => {
        if (valid) {
          this.loading = true;
          let resBody = new tranGroup();
          resBody.data.AppNum = this.formInline.appnum;
          resBody.data.TranGroupNum = this.formInline.trangroupnum;
          resBody.data.TranGroupName = this.formInline.trangroupname;
          resBody.data.TranGroupClass = this.formInline.trangroupclass;
          resBody.data.LegalPersonNum = this.formInline.legalpersonnum;
          resBody.data.EffeDate = this.formInline.effedate;
          resBody.data.ExpiDate = this.formInline.expidate;
          resBody.data.TranGroupStatus = this.formInline.trangroupstatus;
          resBody.data.SortNum = this.formInline.sortnum;
          resBody.data.OperType = "M"; // 操作类型
          request(resBody)
            .then(response => {
              if (response.SYS_HEAD.ReturnCode === "000000") {
                this.loading = false;
                this.$message({
                  type: "success",
                  message: "交易组修改成功!"
                });
                this.isShow = false;
                this.$emit("refreshBrand");
              } else {
                this.loading = false;
                this.$message({
                  type: "error",
                  message: response.SYS_HEAD.ReturnMessage
                });
              }
            })
            .catch(error => {
              this.loading = false;
              console.log(error);
            });
        } else {
          this.$message({
            type: "warning",
            message: "必输项不能为空"
          });
          return false;
        }
      });
    },
    closeDialog(){
      this.isShow = false;
      this.$emit("refreshBrand");
    }
  }
};
</script>
<style lang="sass" scoped>

</style>
